package com.hmall.search.web;

import com.hmall.common.feign.ItemClient;
import com.hmall.search.pojo.Order;
import com.hmall.search.pojo.OrderPayload;
import com.hmall.search.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
@RequestMapping("order")
public class OrderController {

   @Autowired
   private IOrderService orderService;
   @Autowired
   private ItemClient itemClient;
   @Autowired
   private RabbitTemplate rabbitTemplate;

   @GetMapping("{id}")
   public Order queryOrderById(@PathVariable("id") Long orderId) {
      return orderService.getById(orderId);
   }


   @PostMapping
   public Long submit(@RequestBody OrderPayload orderPayload){

     Order order=  orderService.submit(orderPayload);


     log.warn("消息对列===========》");
     rabbitTemplate.convertAndSend("X","XB","消息来自TTL"+orderPayload);
      return order.getId();

   }



}
